<template>
	<view>
		<view class="" style="padding: 20px;margin: 10px;height: 70vh; border-radius: 10px; box-shadow: 0 0 20px black;position: relative;">
			
		
			<uni-forms :modelValue="form" :rules="rules" ref="formRef"  style="margin: 50px;">
				<uni-forms ref="valiForm" :rules="rules" :modelValue="form">
					<span style="margin-bottom: 10px; margin-left: 10px;">内容</span>
					<uni-forms-item  name="content">
						<uni-easyinput type="textarea" v-model="form.content" placeholder="请评价您的留言~" />
					</uni-forms-item>
					
					
					
					<uni-forms-item  name="star">
					<uni-section title="评分" type="line" padding>
								<uni-rate allow-half v-model="form.star" @change="onChange" />
					</uni-section>
					</uni-forms-item>
					
					
				</uni-forms>
			</uni-forms> 
			<button type="primary" @click="submit('valiForm')" style="margin-top: 30px; width: 30vw; background-color: blue;">提交</button>
			
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderNo:'',
				businessId:'',
				userId:uni.getStorageSync('xm-user').id,
				form: {
					userId:'',
					businessId:'',
					orderId:'',
					content:'',
				},
								rules: {
								  content: {
								    rules: [{
								      required: true,
								      errorMessage: '请填写内容',
								    }]
								  },
								  star: {
								    rules: [{
								      required: true,
								      errorMessage: '请评分',
								    }]
								  }
								}
			
			
			
			}},
			
		onLoad(option){
			
			this.orderNo = option.orderNo
			this.form.businessId = option.businessId
			this.form.userId = this.userId
			this.form.orderId = option.orderNo
		},
		methods: {
			submit(ref) {
							this.$refs[ref].validate().then(res => {
								
								this.$request.post('/comment/add',this.form).then(res =>{
									if(res.code == 200){
										//跟新订单状态
										var orderStatus = {
											status:'已完成',
											isFinished:'6',
											orderNo:this.orderNo
										}
										
										this.$request.post('/orders/updateStatusByOrderNo/',orderStatus).then(res=>{
											if(res.code == 200){
												uni.showToast({
													title: `评价成功~`,
													icon:"success"
												})
													setTimeout(()=>{
															uni.navigateBack()
													},1000)
												
											}
										})
										
									}
								})
						
						
						
				
								
						
								
							}).catch(err => {
								console.log('err', err);
							})
						},
						
			onChange(e) {
						
						},
			
			
			
			
		}
	}
</script>

